<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  函数式编程 函数柯里化
  收集一部分参数，等到运行条件时候再去执行
  <script>
    // 柯里化
    function curry(fn, ...args) {
      // fn需要的参数是否够了
      if (args.length >= fn.length) {
        // 如果够了，直接执行fn并返回
        return fn(...args)
      }
      // 递归调用
      return (...rest) => {
        return curry(fn, ...args, ...rest)
      }
    }

    const add = (x, y, z) => {
      return x + y + z
    }

    // const curryAdd = curry(add, 1, 3)
    // console.log(curryAdd(3));

    const curryAdd = curry(add)
    console.log(curryAdd(1)(2)(3));


  </script>
</body>

</html>